package yxy.game.pm2.module.wuchao.event;

import yxy.apple.util.RandomStringUtility;
import yxy.game.pm2.message.WuchaoMessage;
import yxy.game.pm2.module.wuchao.WuchaoModule;

public class WuchaoEvent {

	static public enum EventType {
		NewGoods(1), // 商店新品
		Guess(2), // 竞猜
		Chest(3), // 宝箱
		Drop(4), // 掉落
		Quiz(5), // 答题
		Enemy(6), // 敌人
		Boss(7), // BOSS
		;

		private int number;

		private EventType(int number) {
			this.number = number;
		}

		public int getNumber() {
			return number;
		}

		static public EventType forNumber(int value) {
			switch (value) {
			case 1:
				return NewGoods;
			case 2:
				return Guess;
			case 3:
				return Chest;
			case 4:
				return Drop;
			case 5:
				return Quiz;
			case 6:
				return Enemy;
			case 7:
				return Boss;
			default:
				return null;
			}
		}
	}

	private String code; // 事件代号
	private int level;// 事件层级
	private boolean over; // 事件结束

	public void setCode(String code) {
		this.code = code;
	}

	public String getCode() {
		return code;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public boolean isOver() {
		return over;
	}

	public void setOver(boolean over) {
		this.over = over;
	}

	public WuchaoMessage.WuchaoEvent packageInfo() {
		WuchaoMessage.WuchaoEvent.Builder builder = WuchaoMessage.WuchaoEvent.newBuilder();
		builder.setType(WuchaoMessage.WuchaoEventType.forNumber(getEventType().getNumber()));
		builder.setCode(getCode());
		builder.setLevel(getLevel());
		_packageInfo(builder);
		return builder.build();
	}

	public EventType getEventType() {
		return null;
	}

	protected void _packageInfo(WuchaoMessage.WuchaoEvent.Builder builder) {
		//
	}

	public static String randomCode(WuchaoModule wuchaoModule) {
		String code = randomCode();
		while (wuchaoModule.getEvents().containsKey(code)) {
			code = randomCode();
		}
		return code;
	}

	private static String randomCode() {
		return String.format("we%s", RandomStringUtility.randomLowerCase(4));

	}
}
